<?php


$ignoreAuth = true;
include_once("../globals.php");
include_once("$srcdir/sha1.js");
include_once("$srcdir/sql.inc");
include_once("$srcdir/md5.js");
include_once("$srcdir/md5php.js");


?>
<html>
    <head>
        <title>Telemedicina Bolivar</title>
        <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />               
        <script language='JavaScript' src="../../library/js/jquery-1.7.2.min.js"></script>

        <script type="text/javascript" src="../../library/js/jquery.gritter.min.js"></script>
        <link rel="stylesheet" type="text/css" href="../themes/jquery.gritter.css" />
        <link rel="stylesheet" type="text/css" href="../themes/bootstrap.css?v=2" />
        <link rel="stylesheet" type="text/css" href="../themes/whmcs.css?v=3" />
        <link rel="stylesheet" type="text/css" href="../themes/brand.css" />
        <link rel="stylesheet" type="text/css" href="../themes/bjqs.css" />

        <script src="../js/whmcs.js?v=2"></script>
        <script src="../js/bootstrap.js?v=2"></script>
        <script src="../js/bjqs-1.3.min.js"></script>

        <script language='JavaScript'>

            //VicarePlus :: Validation function for checking the hashing algorithm used for encrypting password
            function chk_hash_fn()
            {
                var str = document.forms[0].authUser.value;
                $.ajax({
                    url: "validateUser.php?u=" + str,
                    context: document.body,
                    success: function(data) {
                        if (data == 0) //VicarePlus :: If the hashing algorithm is 'MD5'
                        {
                            document.forms[0].authPass.value = md5php(document.forms[0].clearPass.value);
                            document.forms[0].authNewPass.value = md5php(document.forms[0].clearPass.value);
                        }
                        else  //VicarePlus :: If the hashing algorithm is 'SHA1'
                        {
                            document.forms[0].authPass.value = md5php(document.forms[0].clearPass.value);
                            document.forms[0].authNewPass.value = md5php(document.forms[0].clearPass.value);
                        }
                        document.forms[0].clearPass.value = '';
                        document.login_form.submit();
                    }
                });
            }

            function imsubmitted() {
<?php if (!empty($GLOBALS['restore_sessions'])) { ?>
                    // Delete the session cookie by setting its expiration date in the past.
                    // This forces the server to create a new session ID.
                    var olddate = new Date();
                    olddate.setFullYear(olddate.getFullYear() - 1);
                    document.cookie = '<?php echo session_name() . '=' . session_id() ?>; path=/; expires=' + olddate.toGMTString();
<?php } ?>
                return false; //Currently the submit action is handled by the chk_hash_fn() function itself.
            }

            jQuery(document).ready(function($) {

                $('#banner-fade').bjqs({
                    animtype: 'slide',
                    height: 280,
                    width: 560,
                    responsive: true,
                    showcontrols : false,
                    randomstart: true,
                    nexttext: '>>', // Text for 'next' button (can use HTML)
                    prevtext: '<<', // Text for 'previous' button (can use HTML)
                    keyboardnav: true, // enable keyboard navigation
                    hoverpause: true // pause the slider on hover
                });

                $('#sld').attr({style: "float:left;"});

            });

        </script>

    </head>
    <body class="main_bg" onload="javascript:document.login_form.authUser.focus();" >

        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <div class="nav-collapse">

                        <ul class="nav pull-left">
                            
                        </ul>
                    </div><!-- /.nav-collapse -->
                </div>
            </div><!-- /navbar-inner -->
        </div>

        <div style="margin-top: 0px; margin-right: auto; margin-left: auto; clear: both; width: 960px;">
            <ul style="margin: 20px">
                <li id="sld"><div id="reg">
                        <div id="banner-fade">

                            <!-- start Basic Jquery Slider -->
                            <ul class="bjqs">
                                <li><img src="img/banner01.jpg" title="Un sistema ajustado a su necesidad"></li>
                                <li><img src="img/banner02.jpg" title="Centralizaci&oacute;n de los historiales cl&iacute;nicos de los pacientes"></li>
                                <li><img src="img/banner03.jpg" title="Accese desde cualquier parte del mundo"></li>
                            </ul>
                            <!-- end Basic jQuery Slider -->

                        </div>
                        <!-- End outer wrapper -->
                    </div></li>
                <li id="lg" style="float: right;"><div id="login" style="float: right; margin-bottom: 40px;">
                        <div id="whmcsheader">
                            <div class="row">
                                <div class="span12">
                                    <div id="whmcstxtlogo"><a href="#">Telemedicina Bolivar</a></div>
                                    <div id="whmcsimglogo"><a href="#"><img width="326" height="130" alt="Salud a un Clic" src="<?php echo $rootdir; ?>/pic/logo-bolivar.png"></a></div>
                                </div>
                            </div>
                        </div>
                        <div class="whmcscontainer">
                            <div class="row">
                                <div class="span12">
                                    <div class="row">
                                        <div class="span6 offset3">
                                           <form method="POST"
                                                  action="../main/main_screen.php?auth=login&site=<?php echo htmlspecialchars($_SESSION['site_id']); ?>"
                                                  target="_top" name="login_form" onsubmit="return imsubmitted();">

                                                <?php
                                                // collect groups
                                                $res = sqlStatement("select distinct name from groups");
                                                for ($iter = 0; $row = sqlFetchArray($res); $iter++)
                                                    $result[$iter] = $row;
                                                if (count($result) == 1) {
                                                    $resvalue = $result[0]{"name"};
                                                    echo "<input type='hidden' name='authProvider' value='$resvalue' />\n";
                                                }
                                                // collect default language id
                                                $res2 = sqlStatement("select * from lang_languages where lang_description = '" . $GLOBALS['language_default'] . "'");
                                                for ($iter = 0; $row = sqlFetchArray($res2); $iter++)
                                                    $result2[$iter] = $row;
                                                if (count($result2) == 1) {
                                                    $defaultLangID = $result2[0]{"lang_id"};
                                                    $defaultLangName = $result2[0]{"lang_description"};
                                                } else {
                                                    //default to english if any problems
                                                    $defaultLangID = 1;
                                                    $defaultLangName = "English";
                                                }
                                                // set session variable to default so login information appears in default language
                                                $_SESSION['language_choice'] = $defaultLangID;
                                                // collect languages if showing language menu
                                                if ($GLOBALS['language_menu_login']) {

                                                    // sorting order of language titles depends on language translation options.
                                                    $mainLangID = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
                                                    if ($mainLangID == '1' && !empty($GLOBALS['skip_english_translation'])) {
                                                        $sql = "SELECT * FROM lang_languages ORDER BY lang_description, lang_id";
                                                        $res3 = SqlStatement($sql);
                                                    } else {
                                                        // Use and sort by the translated language name.
                                                        $sql = "SELECT ll.lang_id, " .
                                                                "IF(LENGTH(ld.definition),ld.definition,ll.lang_description) AS trans_lang_description, " .
                                                                "ll.lang_description " .
                                                                "FROM lang_languages AS ll " .
                                                                "LEFT JOIN lang_constants AS lc ON lc.constant_name = ll.lang_description " .
                                                                "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
                                                                "ld.lang_id = '$mainLangID' " .
                                                                "ORDER BY IF(LENGTH(ld.definition),ld.definition,ll.lang_description), ll.lang_id";
                                                        $res3 = SqlStatement($sql);
                                                    }

                                                    for ($iter = 0; $row = sqlFetchArray($res3); $iter++)
                                                        $result3[$iter] = $row;
                                                    if (count($result3) == 1) {
                                                        //default to english if only return one language
                                                        echo "<input type='hidden' name='languageChoice' value='1' />\n";
                                                    }
                                                } else {
                                                    echo "<input type='hidden' name='languageChoice' value='" . $defaultLangID . "' />\n";
                                                }
                                                ?>

                                                <div class="logincontainer">
                                                    <fieldset class="control-group">
                                                        <?php if (count($result) != 1) { ?>
                                                            <div class="control-group" style="display:none;">
                                                                <label for="username" class="control-label"><?php xl('Group:', 'e'); ?></label>
                                                                <div class="controls">
                                                                    <select name=authProvider>
                                                                        <?php
                                                                        foreach ($result as $iter) {
                                                                            echo "<option value='" . $iter{"name"} . "'>" . $iter{"name"} . "</option>\n";
                                                                        }
                                                                        ?>
                                                                    </select>
                                                                </div>
                                                            </div>
                                                        <?php } ?>

                                                        <?php if (isset($_SESSION['loginfailure']) && ($_SESSION['loginfailure'] == 1)): ?>
                                                            <div style="text-align: center; margin: 0px auto 15px; border: 2px dashed rgb(251, 84, 84); color: rgb(86, 79, 79); font-weight: bold; padding: 5px; width: 75%; background-color: rgb(249, 216, 209);">
                                                                Usuario o contrase&ntilde;a inv&aacute;lidas.
                                                            </div>
                                                        <?php endif; ?>

                                                        <?php if (isset($_SESSION['relogin']) && ($_SESSION['relogin'] == 1)): ?>
                                                            <td colspan='2' class='text' style='color:red;background-color:#dfdfdf;border:solid 1px #bfbfbf;text-align:center'>
                                                                <b><?php echo xl('Password security has recently been upgraded.'); ?><br>
                                                                    <?php echo xl('Please login again.'); ?></b>
                                                                <?php unset($_SESSION['relogin']); ?>
                                                            </td>
                                                        <?php endif; ?>

                                                        <div class="control-group">
                                                            <label for="username" class="control-label"><?php xl('Username:', 'e'); ?></label>
                                                            <div class="controls">
                                                                <input class="input-xlarge" type="text" size="10" name="authUser">
                                                            </div>
                                                        </div>

                                                        <div class="control-group">
                                                            <label for="password" class="control-label"><?php xl('Password:', 'e'); ?></label>
                                                            <div class="controls">
                                                                <input class="input-xlarge" type="password" size="10" name="clearPass">
                                                                <input type="hidden" name="authPass">
                                                                <input type="hidden" name="authNewPass">
                                                            </div>
                                                        </div>
                                                        <?php
                                                        if ($GLOBALS['language_menu_login']) {
                                                            if (count($result3) != 1) {
                                                                ?>
                                                                <div class="control-group">
                                                                    <label for="pass_new" class="control-label"><?php xl('Language', 'e'); ?>:</label>
                                                                    <div class="controls">
                                                                        <select class="entryfield" name=languageChoice size="1">
                                                                            <?php
                                                                            echo "<option selected='selected' value='" . $defaultLangID . "'>" . xl('Default', '', '', ' -') . xl($defaultLangName, '', ' ') . "</option>\n";
                                                                            foreach ($result3 as $iter) {
                                                                                if ($GLOBALS['language_menu_showall']) {
                                                                                    if (!$GLOBALS['allow_debug_language'] && $iter[lang_description] == 'dummy')
                                                                                        continue; // skip the dummy language
                                                                                    echo "<option value='" . $iter['lang_id'] . "'>" . $iter['trans_lang_description'] . "</option>\n";
                                                                                }
                                                                                else {
                                                                                    if (in_array($iter[lang_description], $GLOBALS['language_menu_show'])) {
                                                                                        if (!$GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy')
                                                                                            continue; // skip the dummy language
                                                                                        echo "<option value='" . $iter['lang_id'] . "'>" . $iter['trans_lang_description'] . "</option>\n";
                                                                                    }
                                                                                }
                                                                            }
                                                                            ?>
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                                <?php
                                                            }
                                                        }
                                                        ?>
                                                        <div class="control-group">
                                                            <div class="controls" style="text-align: center;">
                                                                <?php if (isset($GLOBALS['use_adldap_auth']) && ($GLOBALS['use_adldap_auth'] == true)): ?>
                                                                    <input class="btn btn-primary btn-large" type="submit" onClick="javascript:this.form.authPass.value = SHA1(this.form.clearPass.value);" value="<?php xl('Login', 'e'); ?>">
                                                                <?php else: ?>
                                                                    <input class="btn btn-primary btn-large" type="submit" onClick="chk_hash_fn();" value="<?php xl('Login', 'e'); ?>">
                                                                <?php endif; ?>
                                                            </div>
                                                        </div>

                                                        <div class="version" style="font-size: 11px; text-align: center;">
                                                            <?php echo "v$openemr_version" ?>
                                                        </div>
                                                        <?php
                                                        $ip = $_SERVER['REMOTE_ADDR'];
                                                        ?>           
                                                    </fieldset>
                                                </div>
                                            </form>
                                            <script type="text/javascript">$("#username").focus();</script>

                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>

                    </div></li>                
            </ul>


        </div>

        <footer id="footer"></footer>

    </body>
</html>